home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Games / Arashi 1.1.1 / source code / Game Source / jam src / PlayOptions.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-15  |  6.9 KB  |  267 lines  |  [TEXT/KAHL]

  1. /*/
  2.      Project Arashi: PlayOptions.c
  3.      Major release: Version 1.1d2, 9/5/95
  4.  
  5.      Last modification: Monday, March 15, 1993, 20:00
  6.      Created: Sunday, March 17, 1991, 0:29
  7.  
  8.      Copyright © 1991-1993, Juri Munkki
  9. /*/
  10.  
  11. #define        MAINOPTIONS
  12. #include    "VA.h"
  13. #include    "PlayOptions.h"
  14. #include    "ScreenSelect.h"
  15. #include    <GestaltEqu.h>
  16.  
  17. DialogPtr            StartDialog;
  18. PlayOptionsRecord    **OptionsHandle;
  19. int                    OptionsResourceRef;
  20.  
  21. enum    /*    Dialog item numbers:    */
  22. {    FunctionButtons,        StartButton,
  23.                             QuitButton,
  24.     StaticMoveOptions,        RelativeMove,
  25.                             AbsoluteMove,
  26.     StaticSensitivity,        HighSensitivity,
  27.                             MediumSensitivity,
  28.                             LowSensitivity,
  29.                             VeryLowSensitivity,
  30.     StaticDisplayOptions,     BlankUnusedOption,
  31.                             MonochromeOption,
  32.     StaticRotationDirect,    RightClockwise,
  33.                             LeftClockwise,
  34.                             UpClockwise,
  35.                             DownClockwise,
  36.     StaticSoundOptions,        DisableSound,
  37.                             NoLoudSounds,
  38.     StaticHelpScreen,
  39.                             VerticalScreen,
  40.                             Sys607Sound,
  41.     StaticRestartMode,        ArcadeRestart,        /* ( mz) */
  42.                             EasyRestart,
  43.                             ShowFuseScores,        /* (mz) */
  44.                             
  45.                             MoreInfoButton,        /* mz */
  46.                             
  47.                             NoBackgroundTasks
  48.     
  49.                         
  50.         /*    ResEdit 2.1 is incredible!    */
  51. };
  52.  
  53.  
  54. /*
  55. >>    SetItemEnable is a useful little subroutine for setting
  56. >>    the hiliting dialog items.
  57. */
  58. void    SetItemEnable(dialog,num,value)
  59. DialogPtr    dialog;
  60. int            num;
  61. int            value;
  62. {
  63.     Rect            Garbage;
  64.     ControlHandle    ItemH;
  65.     char            str[256];
  66.  
  67.     GetDItem(dialog,num,&Garbage,&ItemH,&Garbage);
  68.     HiliteControl(ItemH,value);
  69. }
  70.  
  71. /*
  72. >>    SetItemValue is a useful little subroutine for setting
  73. >>    and resetting dialog button values.
  74. */
  75. void    SetItemValue(dialog,num,value)
  76. DialogPtr    dialog;
  77. int            num,value;
  78. {
  79.     Rect            Garbage;
  80.     ControlHandle    ItemH;
  81.  
  82.     GetDItem(dialog,num,&Garbage,&ItemH,&Garbage);
  83.     if(GetCtlValue(ItemH) != value)
  84.         SetCtlValue(ItemH,value);
  85. }
  86. /*
  87. >>    OpenDefaults tries to open the defaults
  88. >>    file from the system folder or the folder
  89. >>    that the program is located in. It returns
  90. >>    the reference number.
  91. */
  92. int        OpenDefaults()
  93. {
  94.     register    Handle    temp;
  95.     register    int        theref;
  96.     
  97.     temp=(void *)GetString(OPTIONSFILENAMESTRING);
  98.     HLock(temp);
  99.     theref=OpenResFile(*temp);
  100.  
  101.     if(theref==-1) theref=0;
  102.  
  103.     HUnlock(temp);
  104.     ReleaseResource(temp);
  105.  
  106.     return theref;
  107. }
  108.  
  109. void    SetStartItem(num,value)
  110. int        num,value;
  111. {
  112.     SetItemValue(StartDialog,num,value);
  113. }
  114.  
  115. void    DataToRadioButtons()
  116. {
  117.     int        i;
  118.     long            myFeature;
  119.     
  120.     
  121.     /* Now do check for System Version 6.0.7 for sound */
  122.     if(Gestalt(gestaltSystemVersion, &myFeature))
  123.     {    
  124.         ParamText("\pARASHI encountered an unrecoverable _GESTALT error.",nil,nil,nil);
  125.         Alert(131,0);
  126.         ExitToShell();
  127.     }
  128.     if (myFeature < 0x0607)
  129.     {
  130.         PlayOptions->sys607Sound = 0;
  131.         SetItemEnable(StartDialog,Sys607Sound,255);
  132.     }
  133.  
  134.     SetStartItem(RelativeMove,        !PlayOptions->absMoveFlag);
  135.     SetStartItem(AbsoluteMove,        PlayOptions->absMoveFlag);
  136.  
  137.     SetStartItem(HighSensitivity,    PlayOptions->mouseSensitivity == 7);
  138.     SetStartItem(MediumSensitivity,    PlayOptions->mouseSensitivity == 4);
  139.     SetStartItem(LowSensitivity,    PlayOptions->mouseSensitivity == 3);
  140.     SetStartItem(VeryLowSensitivity,PlayOptions->mouseSensitivity == 2);
  141.     
  142.     SetStartItem(RightClockwise,    PlayOptions->rotationType == 0);
  143.     SetStartItem(LeftClockwise,        PlayOptions->rotationType == 1);
  144.     SetStartItem(UpClockwise,        PlayOptions->rotationType == 2);
  145.     SetStartItem(DownClockwise,        PlayOptions->rotationType == 3);
  146.  
  147.     SetStartItem(BlankUnusedOption,    PlayOptions->blankUnused);
  148.     SetStartItem(MonochromeOption,    PlayOptions->monochrome);
  149.     SetStartItem(VerticalScreen,    PlayOptions->verticalGame);
  150.     SetStartItem(DisableSound,        PlayOptions->soundOff);
  151.     SetStartItem(NoLoudSounds,        PlayOptions->noLoudSounds);
  152.     SetStartItem(Sys607Sound,        PlayOptions->sys607Sound);
  153.     
  154.     SetStartItem(ArcadeRestart,        PlayOptions->restart == 0);   /* (mz) */
  155.     SetStartItem(EasyRestart,        PlayOptions->restart == 1);
  156.     SetStartItem(ShowFuseScores,    PlayOptions->showfscores);
  157.     SetStartItem(NoBackgroundTasks,    PlayOptions->noBackgroundTasks);
  158.         
  159.     
  160.     for(i=RightClockwise;i<=DownClockwise;i++)
  161.     {    SetItemEnable(StartDialog,i,PlayOptions->absMoveFlag?0:255);
  162.     }
  163. }
  164.  
  165. int        DoStartupDialog(item)
  166. int        item;
  167. {
  168.     register    int        done=NotDone;
  169.     
  170.     switch(item)
  171.     {
  172.         case RelativeMove:        PlayOptions->absMoveFlag=0;                            break;
  173.         case AbsoluteMove:        PlayOptions->absMoveFlag=1;                            break;
  174.  
  175.         case HighSensitivity:    PlayOptions->mouseSensitivity=7;                    break;
  176.         case MediumSensitivity:    PlayOptions->mouseSensitivity=4;                    break;
  177.         case LowSensitivity:    PlayOptions->mouseSensitivity=3;                    break;
  178.         case VeryLowSensitivity:PlayOptions->mouseSensitivity=2;                    break;
  179.  
  180.         case BlankUnusedOption:    PlayOptions->blankUnused= !PlayOptions->blankUnused;break;
  181.         case MonochromeOption:    PlayOptions->monochrome= !PlayOptions->monochrome;    break;
  182.         case VerticalScreen:    PlayOptions->verticalGame=!PlayOptions->verticalGame;break;
  183.         case DisableSound:        PlayOptions->soundOff= !PlayOptions->soundOff;        break;
  184.         case NoLoudSounds:        PlayOptions->noLoudSounds= !PlayOptions->noLoudSounds;break;
  185.         case Sys607Sound:        PlayOptions->sys607Sound= !PlayOptions->sys607Sound;break;
  186.         
  187.         case RightClockwise:    PlayOptions->rotationType=0;                        break;
  188.         case LeftClockwise:        PlayOptions->rotationType=1;                        break;
  189.         case UpClockwise:        PlayOptions->rotationType=2;                        break;
  190.         case DownClockwise:        PlayOptions->rotationType=3;                        break;
  191.         
  192.         case ArcadeRestart:        PlayOptions->restart=0;                              break;
  193.         case EasyRestart:        PlayOptions->restart=1;                                break;
  194.         
  195.         case ShowFuseScores:    PlayOptions->showfscores= !PlayOptions->showfscores;break;            
  196.         case StartButton:        done=DefaultDone;                                    break;
  197.         case QuitButton:        done=QuitDone;                                        break;
  198.         case MoreInfoButton:    MoreInfo();                                            break;
  199.         case NoBackgroundTasks:    PlayOptions->noBackgroundTasks= !PlayOptions->noBackgroundTasks;break;
  200.     }
  201.     
  202.     DataToRadioButtons();
  203.     return    done;
  204. }
  205.  
  206. void    OptionsUpdate(ScreenAvailable)
  207. int        ScreenAvailable;
  208. {
  209.     SetItemEnable(StartDialog, StartButton, ScreenAvailable ? 0 : 255);
  210. }
  211.  
  212. void    CenterWindow(wind)
  213. WindowPtr    wind;
  214. {
  215.     GDHandle    GDev;
  216.     Rect        MainScreenRect;
  217.     Point        TopLeft;
  218.     GrafPtr        Saved;
  219.     
  220.     GDev=GetMainDevice();
  221.     MainScreenRect=(*GDev)->gdRect;
  222.     
  223.     GetPort(&Saved);
  224.     SetPort(wind);
  225.     TopLeft.h=0;
  226.     TopLeft.v=0;
  227.     LocalToGlobal(&TopLeft);
  228.     
  229.     if(MainScreenRect.bottom > 400)
  230.     {    TopLeft.v += 40;
  231.     }
  232.         
  233.     MoveWindow(wind,(MainScreenRect.right-wind->portRect.right)/2,TopLeft.v,0);
  234.     
  235.     SetPort(&Saved);
  236. }
  237.  
  238. void    CreateOptionsDialog()
  239. {
  240.     OptionsResourceRef=OpenDefaults();
  241.  
  242.     OptionsHandle = (PlayOptionsRecord **) GetResource('DFLT',128);
  243.     
  244.     if(GetHandleSize(OptionsHandle)<sizeof(PlayOptionsRecord))
  245.         SetHandleSize(OptionsHandle,sizeof(PlayOptionsRecord));
  246.  
  247.     HLock(OptionsHandle);
  248.     PlayOptions= *OptionsHandle;
  249.  
  250.     StartDialog=GetNewDialog(OPTIONSDIALOG,0,(void *)-1);
  251.     CenterWindow(StartDialog);
  252.     DataToRadioButtons();
  253.     ShowWindow(StartDialog);
  254. }
  255.  
  256. void    CloseOptionsDialog()
  257. {
  258.     DisposDialog(StartDialog);
  259.     ChangedResource(OptionsHandle);
  260.     WriteResource(OptionsHandle);
  261.     if(OptionsResourceRef)
  262.     {    DetachResource(OptionsHandle);
  263.         CloseResFile(OptionsResourceRef);
  264.     }
  265.     
  266.     VA.monochrome = PlayOptions->monochrome;
  267. }